console.log('starting notes.js');


const fs = require('fs');


var addNote = (title, body) => {
    console.log('Adding note', title, body);
    let notes = [];
    let note = {
        title,
        body,
    };

    try {
        let noteString = fs.readFileSync('note-data.json');
        notes = JSON.parse(noteString);

    } catch (e) {

    }

    let duplicateNotes = notes.filter((note) => note.title === title);
    if(duplicateNotes.length === 0) {
        notes.push(note);
        fs.writeFileSync('note-data.json', JSON.stringify(notes));

    }

}

var getNote = (title) => {
    console.log('Getting note', title);
}

var getAll = () => {
    console.log('Getting all notes');
}

let removeNote = (title) => {
    console.log('Removing title', title);
}
module.exports = {
    addNote,
    getAll,
    getNote,
    removeNote,
}
